﻿using System;
using System.Web;
using System.Net.Mail;
using CE.Company;

/// <summary>
/// Summary description for MailManager
/// </summary>
namespace CE.Mail
{
    public class MyMailManager
    {
        #region Private Variable
        private MailMessage mail = null;
        private MailAddress mailAddress = null;
        private SmtpClient mailClient = null;
        private int clientPort = -1;
        private string clientHost = String.Empty;
        private bool isEnabledSsl = false;
        private int mailType = -1;
        private string mailBody = "";
        private MailPriority mailPriority = MailPriority.Normal;

        static string smtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPHostName");
        static string smtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPPort");
        static string smtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPAccount");
        static string smtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPDisplayName");
        static string smtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPReplyTo");
        static string smtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPAuthCode");
        static bool smtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.SMTPSslEnable"));
        static string _IsLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.IsCXLive");
        static string _addToSubjectTitle = "[TS] ";
        #endregion

        public MyMailManager()
        {
            mailClient = new SmtpClient();
            mailClient.Host = "smtp.jaring.my";
            mailClient.Port = 587;
            mailClient.EnableSsl = false;
        }

        public MyMailManager(string HostName, string Port, bool EnableSSL, string Account, string AuthCode)
        {
            smtphost = HostName;
            smtpenablessl = EnableSSL;
            smtpport = Port;
            smtpaccount = Account;
            smtpauthcode = AuthCode;
        }

        public static bool SendProposalCompleteNotification(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo)
        {

            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.CompareXpress.com' target='_blank'>CompareXpress.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Download Application Form Instruction</b>";
            mailBody += "<br><br>1) Please click on the following link to download the proposal form: ";
            mailBody += "<a href='" + confirmUrl + "'>Click Here</a>.";
            mailBody += "<br>2) Enter your user ID and password to securely download the completed form details.";
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' />";
            mailBody += "<br><b>CompareXpress Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl);
            return _result;
        }

        public static bool SendProposalCompleteNotificationWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;
            //if (myUri.Port != 80 || myUri.Port != 0)
            //{
            //    confirmUrl += ":" + myUri.Port + ConfirmPath;
            //    imgUrl += ":" + myUri.Port;
            //}
            //else
            //{
            confirmUrl += ConfirmPath;
            //}

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.CompareXpress.com' target='_blank'>CompareXpress.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Download Application Form Instruction</b>";
            mailBody += "<br><br>1) Please click on the following link to download the proposal form: ";
            mailBody += "<a href='" + confirmUrl + "'>Click Here</a>.";
            mailBody += "<br>2) Enter your user ID and password to securely download the completed form details.";
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' />";
            mailBody += "<br><b>CompareXpress Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        smtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarLibertyProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to Liberty Insurance.<br><br>";
            mailBody += "Liberty will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@libertyinsurance.com.sg'>motorquotation@libertyinsurance.com.sg</a>.<br><br>";
            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your CompareXpress Team<br/>";
            mailBody += "Customer Support - SG/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.comparexpress.com' target='_blank'>http://www.comparexpress.com</a> :: <a href='mailto:support@comparexpress.com'>support@comparexpress.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        //Sakthi on 13 Jan 2011 -- start
        public static bool SendCarLibertyProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList, string PaymentMode)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to Liberty Insurance.<br><br>";
            mailBody += "Liberty will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@libertyinsurance.com.sg'>motorquotation@libertyinsurance.com.sg</a>.<br><br>";

            if (PaymentMode == "Cash")
            {
                mailBody += "Upon submission, please allow 1-2 working days for Liberty Insurance to process proposal form. Liberty Insurance will inform you via telephone.";
                mailBody += "You will then have to come down in person to make payment before Liberty Insurance issues the CI documents.<br/><br>";

            }
            //Phyo @09/Sep/2011
            //mailBody += "<i><b>TEMPORARY OFFICE RELOCATION</b></i><br><br>";
            //mailBody += "<i>With effect from 15 November 2010, we are operating at 5 Shenton Way #03-00 UIC Building Singapore 068808. Our Telephone and Fax numbers remail unchanged. ";
            //mailBody += "<i>All mails can still be sent to 51 Club St & they will be automatically redirected by Sing Post to our current location at UIC.</i></i><br><br>";
            //mailBody += "<i>Kindly proceed to B1-04 for Motor Insurance Dept & Road Tax Counter.</i><br><br>";
            //mailBody += "<i>Our opending hours: Monday to Friday - 0830am to 1730pm (Car Insurance) / 0830am to 1700pm (Road Tax Collection)</i><br><br>";
            //mailBody += "<i>Any doubt, Kindly contact us with more information.</i><br><br>";

            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your CompareXpress Team<br/>";
            mailBody += "Customer Support - SG/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.comparexpress.com' target='_blank'>http://www.comparexpress.com</a> :: <a href='mailto:support@comparexpress.com'>support@comparexpress.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }
        //Sakthi on 13 Jan 2011 -- end

        public static bool SendCarProposalAttachment(string PName, string ToEmailAddress, string CCEMailAddress, string BCCEMailAddress, string InsType, string Date, string Time, string RefNo, string ProviderCompany, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;
            //if (myUri.Port != 80 || myUri.Port != 0)
            //{
            //    confirmUrl += ":" + myUri.Port + ConfirmPath;
            //    imgUrl += ":" + myUri.Port;
            //}
            //else
            //{
            //    confirmUrl += ConfirmPath;
            //}

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.CompareXpress.com' target='_blank'>CompareXpress.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Check Car Insurance related documents of " + ProviderCompany + " Insurance as attachments.</b>";
            mailBody += "<br><br><br>If you have further queries, please contact us at:";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' />";
            mailBody += "<br><b>CompareXpress Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        PName,
                        ToEmailAddress,
                        CCEMailAddress,
                        BCCEMailAddress,
                        cxformssmtpreplyto,
                        InsType + "Car Insurance Related Documents (Reference No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
            //return true;
        }

        public static bool SendPasswordResetLink(string UserName, string EmailAddress, string AuthSalt, string UniquiId, CE.Global.CEUserType UserType)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "";
            string ConfirmPath = "";
            string userType = "";
            if (UserType == CE.Global.CEUserType.Customer)
            {
                domainUrl = "http://" + myUri.Host;
                userType = "Customer";
                ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ResetCustomerPasswordPath");
            }
            else if (UserType == CE.Global.CEUserType.Provider)
            {
                domainUrl = "https://" + myUri.Host;
                userType = "Provider";
                ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ResetProviderPasswordPath");
            }

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;
            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            string mailBody = "<img src='" + imgUrl + "' /><br>Your Account is : <b>" + UserName + "</b><br>";
            mailBody += "<br><a href='" + confirmUrl + "?authkey=" + AuthSalt + "&uid=" + UniquiId + "'>Click Here</a> to reset your Customer Account's Password.";
            mailBody += "<br><br><br>Thank you very much!";
            mailBody += "<br>Regards,";
            mailBody += "<br>CompareXpress Membership Service";

            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        userType,
                        EmailAddress,
                        "",
                        "",
                        noreplysmtpreplyto,
                        "Password Recovery - CompareXpress.Com",
                        mailBody,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendCARMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string carquotessmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPHostName");
            string carquotessmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPPort");
            string carquotessmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPAccount");
            string carquotessmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPDisplayName");
            string carquotessmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPReplyTo");
            string carquotessmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPAuthCode");
            bool carquotessmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CarQuotesSMTPSslEnable"));

            bool _result = SendMailNew(carquotessmtphost,
                        Convert.ToInt32(carquotessmtpport),
                        carquotessmtpaccount,
                        carquotessmtpauthcode,
                        carquotessmtpdisplayname,
                        carquotessmtpaccount,
                        "Member",
                        EmailAddress,
                        "",
                        "",
                        carquotessmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        carquotessmtpenablessl);
            return _result;
        }

        public static bool SendCRMMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        "",
                        "",
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendCRMMessage(string EmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        "",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendCARRenewalMessage(string EmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string EmailMessage)
        {
            //string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            //string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            //string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            //string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            //string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            //string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            //bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            string cxfeedbacksmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPHostName");
            string cxfeedbacksmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPPort");
            string cxfeedbacksmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPAccount");
            string cxfeedbacksmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPDisplayName");
            string cxfeedbacksmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPReplyTo");
            string cxfeedbacksmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPAuthCode");
            bool cxfeedbacksmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPSslEnable"));

            bool _result = SendMailNew(cxfeedbacksmtphost,
                        Convert.ToInt32(cxfeedbacksmtpport),
                        cxfeedbacksmtpaccount,
                        cxfeedbacksmtpauthcode,
                        cxfeedbacksmtpdisplayname,
                        cxfeedbacksmtpaccount,
                        "",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        cxfeedbacksmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        cxfeedbacksmtpenablessl);

            return _result;
        }

        public static bool SendCRMProviderMessage(string EmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string EmailMessage)
        {
            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        "",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        cxformssmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        cxformssmtpenablessl);
            return _result;
        }

        public static bool SendCRMMessageWithAttachment(string EmailAddress, string EmailSubject, string EmailMessage, string[] fileList)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            bool _result = SendMailNewByAttachments(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        "",
                        "",
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl,
                        fileList);
            return _result;
        }

        public static bool SendFeedBack(string SenderEmailAddress, string EmailAddress, string EmailSubject, string EmailMessage)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;

            string imgUrl = domainUrl;
            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");
            string mailBody = "<img src='" + imgUrl + "' alt='CompareXpress Logo'/><br>";
            mailBody += EmailMessage;

            mailBody += "<br><br><br>Thank you very much!";
            mailBody += "<br>Regards,";
            mailBody += "<br><b>Feedback Mail Service</b>";
            mailBody += "<br><b>CompareXpress.com</b><br>";


            string cxfeedbacksmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPHostName");
            string cxfeedbacksmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPPort");
            string cxfeedbacksmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPAccount");
            string cxfeedbacksmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPDisplayName");
            string cxfeedbacksmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPReplyTo");
            string cxfeedbacksmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPAuthCode");
            bool cxfeedbacksmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFeedBackSMTPSslEnable"));

            bool _result = SendMailNew(cxfeedbacksmtphost,
                        Convert.ToInt32(cxfeedbacksmtpport),
                        cxfeedbacksmtpaccount,
                        cxfeedbacksmtpauthcode,
                        cxfeedbacksmtpdisplayname,
                        cxfeedbacksmtpaccount,
                        "Mail Service",
                        EmailAddress,
                        "",
                        "",
                        cxfeedbacksmtpreplyto,
                        EmailSubject,
                        mailBody,
                        cxfeedbacksmtpenablessl);

            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        "Mail Service",
                        SenderEmailAddress,
                        "",
                        "",
                        noreplysmtpreplyto,
                        "Thank you for your feedback - CompareXpress.com",
                        "Dear Feedback Sender,<br/><br/> Thank you very much for your feedback. <br/><br/> Your Message :" + EmailMessage + " <br /><br />Regards, <br/><img src='" + imgUrl + "' alt='CompareXpress Logo'/><br><b>CompareXpress Team</b>",
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendMailNew(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sCCEmail, string sBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL)
        {
            if (sToName.Length == 0)
                sToName = sToEmail;
            if (sFromName.Length == 0)
                sFromName = sFromEmail;

            //System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();

            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
            //if (fSSL)
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

            //if (sUserName.Length == 0)
            //{
            //    //Ingen auth 
            //}
            //else
            //{
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
            //}

            //Mail.To = sToEmail;
            //Mail.Cc = sCCEmail;
            //Mail.Bcc = sBCCEmail;
            //Mail.From = sFromEmail;
            //Mail.Subject = sHeader;
            //Mail.Body = sMessage;            
            //Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

            try
            {
                if (_IsLive == "1")
                {
                    _addToSubjectTitle = "";
                }
                else
                {
                    _addToSubjectTitle = "[TS] ";
                }
                sHeader = _addToSubjectTitle + sHeader;

                MailMessage Mail = new MailMessage();

                if (sToEmail != "")
                {
                    string[] sGetToEmails = sToEmail.Split(';');

                    foreach (string toemail in sGetToEmails)
                    {
                        if (toemail != "")
                            Mail.To.Add(new MailAddress(toemail));
                    }
                }

                if (sCCEmail != "")
                {
                    string[] sGetCCEmails = sCCEmail.Split(';');

                    foreach (string ccemail in sGetCCEmails)
                    {
                        if (ccemail != "")
                            Mail.CC.Add(new MailAddress(ccemail));
                    }
                }

                if (sBCCEmail != "")
                {
                    string[] sGetBCCEmails = sBCCEmail.Split(';');

                    foreach (string bccemail in sGetBCCEmails)
                    {
                        if (bccemail != "")
                            Mail.Bcc.Add(new MailAddress(bccemail));
                    }

                }

                Mail.From = new MailAddress(sFromEmail, sFromName); ;
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.IsBodyHtml = true;
                Mail.ReplyTo = new MailAddress(sReplyToEmail);

                //System.Web.Mail.SmtpMail.SmtpServer = sHost;
                //System.Web.Mail.SmtpMail.Send(Mail);                

                SmtpClient smtp = new SmtpClient();
                smtp.Port = nPort;
                smtp.Host = sHost;
                smtp.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);

                if (fSSL)
                {
                    smtp.EnableSsl = true;
                }

                object userState = Mail;

                smtp.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
                smtp.SendAsync(Mail, userState);

            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew Exception");

                //string cxerrorsmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPAccount");
                //if (sUserName != cxerrorsmtpaccount)
                //{
                //    string _errorMessage = "<table>";
                //    _errorMessage += "<tr><td>Exception</td><td>:</td><td>" + Ex.ToString() + "</td></tr>";
                //    _errorMessage += "<tr><td>Function</td><td>:</td><td>" + "SendMailNew of MyMailManager" + "</td></tr>";
                //    _errorMessage += "<tr><td>Host</td><td>:</td><td>" + sHost + "</td></tr>";
                //    _errorMessage += "<tr><td>Port</td><td>:</td><td>" + nPort.ToString() + "</td></tr>";
                //    _errorMessage += "<tr><td>User Name</td><td>:</td><td>" + sUserName + "</td></tr>";
                //    _errorMessage += "<tr><td>Password</td><td>:</td><td>" + sPassword + "</td></tr>";
                //    _errorMessage += "<tr><td>From Email</td><td>:</td><td>" + sFromEmail + "</td></tr>";
                //    _errorMessage += "<tr><td>To Email</td><td>:</td><td>" + sToEmail + "</td></tr>";
                //    _errorMessage += "<tr><td>Subject</td><td>:</td><td>" + sHeader + "</td></tr>";
                //    _errorMessage += "<tr><td>Mail Message</td><td>:</td><td>" + sMessage + "</td></tr>";
                //    SendErrorMessage("Mail Sending", _errorMessage);
                //}
                return false;
            }
            return true;
        }

        public static bool SendMailNewByAttachments(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sCCEmail, string sBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL, string[] fileList)
        {
            if (sToName.Length == 0)
                sToName = sToEmail;
            if (sFromName.Length == 0)
                sFromName = sFromEmail;

            //System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();

            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

            //Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
            //if (fSSL)
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

            //if (sUserName.Length == 0)
            //{
            //    //Ingen auth 
            //}
            //else
            //{
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
            //    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
            //}

            //Mail.To = sToEmail;
            //Mail.Cc = sCCEmail;
            //Mail.Bcc = sBCCEmail;
            //Mail.From = sFromEmail;
            //Mail.Subject = sHeader;
            //Mail.Body = sMessage;            
            //Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

            try
            {
                if (_IsLive == "1")
                {
                    _addToSubjectTitle = "";
                }
                else
                {
                    _addToSubjectTitle = "[TS] ";
                }
                sHeader = _addToSubjectTitle + sHeader;

                MailMessage Mail = new MailMessage();

                if (sToEmail != "")
                {
                    string[] sGetToEmails = sToEmail.Split(';');

                    foreach (string toemail in sGetToEmails)
                    {
                        if (toemail != "")
                            Mail.To.Add(new MailAddress(toemail));
                    }
                }

                if (sCCEmail != "")
                {
                    string[] sGetCCEmails = sCCEmail.Split(';');

                    foreach (string ccemail in sGetCCEmails)
                    {
                        if (ccemail != "")
                            Mail.CC.Add(new MailAddress(ccemail));
                    }
                }

                if (sBCCEmail != "")
                {
                    string[] sGetBCCEmails = sBCCEmail.Split(';');

                    foreach (string bccemail in sGetBCCEmails)
                    {
                        if (bccemail != "")
                            Mail.Bcc.Add(new MailAddress(bccemail));
                    }

                }

                Mail.From = new MailAddress(sFromEmail, sFromName); ;
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.IsBodyHtml = true;
                Mail.ReplyTo = new MailAddress(sReplyToEmail);

                for (int i = 0; i < fileList.Length; i++)
                {
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(fileList[i].ToString());
                    Mail.Attachments.Add(attachment);
                }

                //System.Web.Mail.SmtpMail.SmtpServer = sHost;
                //System.Web.Mail.SmtpMail.Send(Mail);                

                SmtpClient smtp = new SmtpClient();
                smtp.Port = nPort;
                smtp.Host = sHost;
                smtp.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);

                if (fSSL)
                {
                    smtp.EnableSsl = true;
                }



                object userState = Mail;

                smtp.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
                smtp.SendAsync(Mail, userState);

            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew Exception");

                //string cxerrorsmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPAccount");
                //if (sUserName != cxerrorsmtpaccount)
                //{
                //    string _errorMessage = "<table>";
                //    _errorMessage += "<tr><td>Exception</td><td>:</td><td>" + Ex.ToString() + "</td></tr>";
                //    _errorMessage += "<tr><td>Function</td><td>:</td><td>" + "SendMailNew of MyMailManager" + "</td></tr>";
                //    _errorMessage += "<tr><td>Host</td><td>:</td><td>" + sHost + "</td></tr>";
                //    _errorMessage += "<tr><td>Port</td><td>:</td><td>" + nPort.ToString() + "</td></tr>";
                //    _errorMessage += "<tr><td>User Name</td><td>:</td><td>" + sUserName + "</td></tr>";
                //    _errorMessage += "<tr><td>Password</td><td>:</td><td>" + sPassword + "</td></tr>";
                //    _errorMessage += "<tr><td>From Email</td><td>:</td><td>" + sFromEmail + "</td></tr>";
                //    _errorMessage += "<tr><td>To Email</td><td>:</td><td>" + sToEmail + "</td></tr>";
                //    _errorMessage += "<tr><td>Subject</td><td>:</td><td>" + sHeader + "</td></tr>";
                //    _errorMessage += "<tr><td>Mail Message</td><td>:</td><td>" + sMessage + "</td></tr>";
                //    SendErrorMessage("Mail Sending", _errorMessage);
                //}
                return false;
            }
            return true;
        }

        static void MailDeliveryComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            //Console.WriteLine("Message \"{0}\".", e.UserState);

            if (e.Error != null)
            {
                try
                {
                    //Get the Original MailMessage object
                    MailMessage mail = (MailMessage)e.UserState;

                    //write out the subject
                    string subject = mail.Subject;

                    System.Text.StringBuilder errorMsg = new System.Text.StringBuilder();
                    errorMsg.Append(string.Format("An error occurred sending message [{0}]. {1}", e.UserState.ToString(), e.Error.Message));

                    if (e.Error.InnerException != null)
                        errorMsg.Append(Environment.NewLine + "Inner exception message: " + e.Error.InnerException.Message);

                    errorMsg.Append(Environment.NewLine + "Subject: " + subject);
                    errorMsg.Append(Environment.NewLine + "Sender: " + mail.Sender.Address.ToString());
                    errorMsg.Append(Environment.NewLine + "Sender Host: " + mail.Sender.Host.ToString());
                    errorMsg.Append(Environment.NewLine + "From : " + mail.From.Address.ToString());
                    errorMsg.Append(Environment.NewLine + "From Host : " + mail.From.Host.ToString());
                    string _toAddresses = "";
                    foreach (MailAddress _msgMail in mail.To)
                    {
                        _toAddresses += _msgMail.Address.ToString() + ";";
                    }
                    errorMsg.Append(Environment.NewLine + "To : " + _toAddresses);
                    CreateMailDeliveryExceptionLog("SendMailNew MailDeliveryComplete Exception", errorMsg);
                }
                catch (Exception Ex)
                {
                    Ex = null;
                }
            }
            else if (e.Cancelled)
            {
                //Console.WriteLine("Sending of email cancelled.");
            }
            else
            {
                //Console.WriteLine("Message sent.");
            }
        }

        public static bool SendWebMailNewByAttachments(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sToCCEmail, string sToBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL, string[] fileList)
        {
            bool _retValue = false;
            try
            {
                if (_IsLive == "1")
                {
                    _addToSubjectTitle = "";
                }
                else
                {
                    _addToSubjectTitle = "[TS] ";
                }
                sHeader = _addToSubjectTitle + sHeader;

                if (sToName.Length == 0)
                    sToName = sToEmail;
                if (sFromName.Length == 0)
                    sFromName = sFromEmail;

                System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
                if (fSSL)
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

                if (sUserName.Length == 0)
                {
                    //Ingen auth 
                }
                else
                {
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
                }


                Mail.To = sToEmail;
                Mail.From = sFromName + "<" + sFromEmail + ">";
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.Cc = sToCCEmail;
                Mail.Bcc = sToBCCEmail;
                Mail.Headers.Add("Reply-To", sReplyToEmail);

                for (int i = 0; i < fileList.Length; i++)
                {
                    Mail.Attachments.Add(new System.Web.Mail.MailAttachment(fileList[i].ToString()));
                }

                Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

                System.Web.Mail.SmtpMail.SmtpServer = sHost;
                System.Web.Mail.SmtpMail.Send(Mail);
                _retValue = true;
            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew By Attachments Exception");
                _retValue = false;
            }

            return _retValue;
        }

        public static bool SendProviderNotificationUpdates(string ToEmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string ProviderName,
            string UserId, string ModuleName, int TransType, string OtherInfo)
        {

            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            string Transaction = "";

            if (TransType == 1)
            {
                Transaction = "Insert";
            }
            else if (TransType == 2)
            {
                Transaction = "Update";
            }
            else
            {
                Transaction = "Delete";
            }

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + ProviderName + " Insurance,<br><br>";
            mailBody += "<br>You have just updated your " + ModuleName + " Page.";
            mailBody += "<br><br>Transaction Type: " + Transaction;
            mailBody += "<br>" + OtherInfo;
            mailBody += "<br>Date: " + CE.Global.General.GetUTCDateTime().ToString();
            mailBody += "<br>UserID: " + UserId;
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' />";
            mailBody += "<br><b>CompareXpress Team</b>";

            bool _result = SendMailNew(smtphost,
                        Convert.ToInt32(smtpport),
                        smtpaccount,
                        smtpauthcode,
                        smtpdisplayname,
                        smtpaccount,
                        "Member",
                        ToEmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        smtpreplyto,
                        EmailSubject,
                        mailBody,
                        smtpenablessl);
            return _result;
        }

        public static bool SendErrorMessage(string TitlePrefix, string EmailMessage)
        {
            string _errormessagereceiver = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ErrorMessageReceiver");

            string cxerrorsmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPHostName");
            string cxerrorsmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPPort");
            string cxerrorsmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPAccount");
            string cxerrorsmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPAuthCode");
            bool cxerrorsmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXErrorSMTPSslEnable"));

            bool _result = SendMailNew(cxerrorsmtphost,
                        Convert.ToInt32(cxerrorsmtpport),
                        cxerrorsmtpaccount,
                        cxerrorsmtpauthcode,
                        "CompareXpress",
                        cxerrorsmtpaccount,
                        TitlePrefix + " CX Error Message Service",
                        _errormessagereceiver,
                        "",
                        "",
                        cxerrorsmtpaccount,
                        TitlePrefix + " Error - " + CE.Global.General.GetUTCDateTime().ToString(),
                        EmailMessage,
                        cxerrorsmtpenablessl);

            return _result;
        }

        private static void CreateExceptionLog(Exception Ex, string EmailSettingInfo, string strLocation)
        {
            String[] _fileContent = new String[7];
            _fileContent[0] = "Email Setting : " + EmailSettingInfo;
            _fileContent[1] = "Source : " + Ex.Source;
            _fileContent[2] = "Date Time : " + CE.Global.General.GetUTCDateTime().ToString();
            _fileContent[3] = "Stack Trace :" + Ex.StackTrace.ToString();
            _fileContent[4] = "Target Site : " + Ex.TargetSite.ToString();
            _fileContent[5] = "Location : " + "MyMailManager - " + strLocation;
            _fileContent[6] = "Message : " + Ex.Message;

            WriteExceptionLog("Mail_", _fileContent);
        }

        private static void WriteExceptionLog(string strPrefixFileName, string[] strException)
        {
            try
            {
                CE.InputOut.MyIO _newFile = new CE.InputOut.MyIO();
                string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
                if (_newFile.CheckDirectory(_filePath))
                {
                    string _curMonth = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00");

                    if (!_newFile.CheckDirectory(_filePath + _curMonth))
                    {
                        if (_newFile.CreateDirectory(_filePath, _curMonth))
                        {
                            _filePath += _curMonth + "\\";
                        }
                    }
                    else
                    {
                        _filePath += _curMonth + "\\";
                    }

                    string _fileName = strPrefixFileName + _curMonth + CE.Global.General.GetUTCDateTime().Day.ToString("00") + CE.Global.General.GetUTCDateTime().Second.ToString("00") + CE.Global.General.GetUTCDateTime().Millisecond.ToString("00") + ".txt";

                    _newFile.WriteNewFile(_filePath, _fileName, strException);
                    _newFile = null;
                }
            }
            catch (Exception Ex)
            {
                Ex = null;
            }
        }

        private static void CreateMailDeliveryExceptionLog(string strLocation, System.Text.StringBuilder ErrorMessage)
        {
            String[] _fileContent = new String[3];
            _fileContent[0] = "Date Time : " + CE.Global.General.GetUTCDateTime().ToString();
            _fileContent[1] = "Location : " + "MyMailManager - " + strLocation;
            _fileContent[2] = "Message : " + ErrorMessage;

            WriteMailDeliveryExceptionLog("MailDelivery_", _fileContent);
        }

        private static void WriteMailDeliveryExceptionLog(string strPrefixFileName, string[] strException)
        {
            try
            {
                CE.InputOut.MyIO _newFile = new CE.InputOut.MyIO();
                string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
                if (_newFile.CheckDirectory(_filePath))
                {
                    string _curMonth = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00");

                    if (!_newFile.CheckDirectory(_filePath + _curMonth))
                    {
                        if (_newFile.CreateDirectory(_filePath, _curMonth))
                        {
                            _filePath += _curMonth + "\\";
                        }
                    }
                    else
                    {
                        _filePath += _curMonth + "\\";
                    }

                    string _fileName = strPrefixFileName + _curMonth + CE.Global.General.GetUTCDateTime().Day.ToString("00") + CE.Global.General.GetUTCDateTime().Second.ToString("00") + CE.Global.General.GetUTCDateTime().Millisecond.ToString("00") + ".txt";

                    _newFile.WriteNewFile(_filePath, _fileName, strException);
                    _newFile = null;
                }
            }
            catch (Exception Ex)
            {
                Ex = null;
            }
        }

        //Sakthi on 20 Jan 2011 - Start
        public static bool SendTIProposalNotification(string PName, string InsType, string RefNo, string Date, string Time, string CustName, string CustEmail,
            string CustContactNo, string PlanName, string PlanType, string TripType, string Destination, string Premium, string Startdate, string EndDate, string QuoteDate,
            string SelectedDate, string EmailAddress, string CCEmail, string BCCEmail, string UserId, string NoofAdults, string NoofChilds)
        {
            //string mailBody = "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='0'>";
            //mailBody += "<tr>";
            //mailBody += "<td>";
            //mailBody += "<br>Dear CX Team,<br><br>";
            //mailBody += "<br>" + PName + " have just received a " + InsType + " quote (Quote No : " + RefNo + ")";
            //mailBody += " online form via <a href='http://www.CompareXpress.com' target='_blank'>CompareXpress.com</a>, dated ";
            //mailBody += Date + " timed " + Time + ".";
            string mailBody = "<br><b>Quote Details</b><br><br>";
            mailBody += "<table style='width: 50%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>";

            //Sakthi on 15 Feb 2011 (Command the If condition)
            //if (UserId != "0")
            //{
            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Customer Name</td>";
            mailBody += "<td width='70%' align='left'>" + CustName + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Email Address</td>";
            mailBody += "<td width='70%' align='left'>" + CustEmail + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Contact No</td>";
            mailBody += "<td width='70%' align='left'>" + CustContactNo + "</td>";
            mailBody += "</tr>";
            //}
            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Plan Name</td>";
            mailBody += "<td width='70%' align='left'>" + PlanName + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Plan Type</td>";
            mailBody += "<td width='70%' align='left'>" + PlanType + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Trip Type</td>";
            mailBody += "<td width='70%' align='left'>" + TripType + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Destination</td>";
            mailBody += "<td width='70%' align='left'>" + Destination + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Premium</td>";
            mailBody += "<td width='70%' align='left'>S$" + Premium + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Travel Start date</td>";
            mailBody += "<td width='70%' align='left'>" + Startdate + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Travel End Date</td>";
            mailBody += "<td width='70%' align='left'>" + EndDate + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Quote Date</td>";
            mailBody += "<td width='70%' align='left'>" + QuoteDate + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Selected Date</td>";
            mailBody += "<td width='70%' align='left'>" + SelectedDate + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Number of Adults</td>";
            mailBody += "<td width='70%' align='left'>" + NoofAdults + "</td>";
            mailBody += "</tr>";

            mailBody += "<tr>";
            mailBody += "<td width='30%' align='left'>Number of Childs</td>";
            mailBody += "<td width='70%' align='left'>" + NoofChilds + "</td>";
            mailBody += "</tr>";

            mailBody += "</table>";

            //mailBody += "</td>";
            //mailBody += "</tr>";
            //mailBody += "</table>";

            //string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            //string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            //string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            //string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            //string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            //string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            //bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            //public static bool SendTIMail(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
            //string sToName, string sToEmail, string sToCCEmail, string sToBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL)

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        PName + " : " + InsType + " Quote - Quote No : " + RefNo,
                        mailBody,
                        cxformssmtpenablessl);
            return _result;
        }

        //public static bool SendTIMail(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        //string sToName, string sToEmail, string sToCCEmail, string sToBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL)
        //{
        //    bool _retValue = false;
        //    try
        //    {
        //        if (_IsLive == "1")
        //        {
        //            _addToSubjectTitle = "";
        //        }
        //        else
        //        {
        //            _addToSubjectTitle = "[TS] ";
        //        }
        //        sHeader = _addToSubjectTitle + sHeader;

        //        if (sToName.Length == 0)
        //            sToName = sToEmail;
        //        if (sFromName.Length == 0)
        //            sFromName = sFromEmail;

        //        System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();
        //        Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
        //        Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

        //        Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
        //        if (fSSL)
        //            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

        //        if (sUserName.Length == 0)
        //        {
        //            //Ingen auth 
        //        }
        //        else
        //        {
        //            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
        //            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
        //            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
        //        }

        //        Mail.To = sToEmail;
        //        Mail.From = sFromName + "<" + sFromEmail + ">";
        //        Mail.Subject = sHeader;
        //        Mail.Body = sMessage;
        //        Mail.Cc = sToCCEmail;
        //        Mail.Bcc = sToBCCEmail;
        //        Mail.Headers.Add("Reply-To", sReplyToEmail);

        //        Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

        //        System.Web.Mail.SmtpMail.SmtpServer = sHost;
        //        System.Web.Mail.SmtpMail.Send(Mail);
        //        _retValue = true;
        //    }
        //    catch (Exception Ex)
        //    {
        //        string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
        //        CreateExceptionLog(Ex, _emailSetting, "SendMailNew By Attachments Exception");
        //        _retValue = false;
        //    }

        //    return _retValue;
        //}

        //Sakthi on 20 Jan 2011 - End


        //Sakthi on 24 Jan 2011 -- start

        public static bool SendCINoMatchFountAttachment(string EmailAddress, string CCEmail, string BCCEmail, string RefNo, string Date, string Time, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear Newstate,<br><br>";
            mailBody += "<br>You have just received a customer requesting for Car Insurance quotes via ";
            mailBody += " <a href='http://www.CompareXpress.com' target='_blank'>CompareXpress.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br>Customer details as attached in Excel. If you have further queries, please contact us at:<br/><br/>";

            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road<br/>";
            mailBody += "#04-06 Technopark @ Chai Chee<br/";
            mailBody += "Singapore 469004<br/>";
            mailBody += "Tel:+65-6591-5339<br/>";
            mailBody += "Fax:+65-6449-8262<br/>";
            mailBody += "Email: <a href='mailto:support@comparexpress.com'>support@comparexpress.com</a><br/>";

            mailBody += "<br>Best Regards,<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' /><br>";
            mailBody += "Your CompareXpress Team<br/>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        "Team",
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                         "Car Insurance : Quote Request (Quote No : " + RefNo + ") - from CompareXpress.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        //Sakthi on 24 Jan 2011 -- end

        //Sakthi on 04 May 2011 -- start
        public static bool SendCXBrokerNotification(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            //string noreplycxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpHostName");
            //string noreplycxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpPort");
            //string noreplycxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpAccount");
            //string noreplycxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpDisplayName");
            //string noreplycxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpReplyTo");
            //string noreplycxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpAuthCode");
            //bool noreplycxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplycxformssmtpSslEnable"));

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));
            string CCEmailAddress = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CC_CINoMatchFoundReceiver");
            string BCCEmailAddress = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.BCC_CINoMatchFoundReceiver");

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        "Member",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        cxformssmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        cxformssmtpenablessl);
            return _result;
        }
        //Sakthi on 04 May 2011 -- end

        //Sakthi on 29 Jun 2011 -- Start

        public static bool SendCallMeMessage(string EmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string EmailMessage)
        {
            //string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            //string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            //string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            //string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            //string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            //string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            //bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                         cxformssmtpaccount,
                         cxformssmtpauthcode,
                         cxformssmtpdisplayname,
                         cxformssmtpaccount,
                        "Member",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                         cxformssmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                         cxformssmtpenablessl);
            return _result;
        }

        //Sakthi on 29 Jun 2011 -- End

        //Sakthi on 16 Nov 2011 - Start
        public static bool SendCXBrokerNotificationWithAttach(string EmailAddress, string EmailSubject, string EmailMessage, string[] fileList)
        {
            //string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPHostName");
            //string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPPort");
            //string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAccount");
            //string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPDisplayName");
            //string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPReplyTo");
            //string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPAuthCode");
            //bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("NoReplySMTPSslEnable"));

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXFormsSMTPSslEnable"));

            string CCEmailAddress = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CC_CINoMatchFoundReceiver");
            string BCCEmailAddress = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BCC_CINoMatchFoundReceiver");

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname,
                        cxformssmtpaccount,
                        "Member",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        cxformssmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        cxformssmtpenablessl,
                        fileList);

            return _result;
        }
        //Sakthi on 16 Nov 2011 -- End
    }
}
